package models;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JPanel;

public class JStatusbar extends JPanel {

	private static final long serialVersionUID = 1L;

	protected JPanel leftPanel;
	protected JPanel rightPanel;

	public JStatusbar() {
		createPartControl();
	}

	protected void createPartControl() {
		setLayout(new BorderLayout());
		setPreferredSize(new Dimension(getWidth(), 25));

		leftPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
		leftPanel.setOpaque(false);
		add(leftPanel, BorderLayout.WEST);

		rightPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 5, 5));
		rightPanel.setOpaque(false);
		add(rightPanel, BorderLayout.EAST);
	}

	public void setLeftComponent(JComponent component) {
		leftPanel.add(component);
	}

	public void addRightComponent(JComponent component) {
		JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0));
		panel.add(new SeparatorPanel(Color.GRAY, Color.WHITE));
		panel.add(component);
		rightPanel.add(panel);
	}

	public void deleteRightComponent(JComponent component) {
		int i = 0;
		search: {
			for (Component cmp : rightPanel.getComponents()) {
				for (Component c : ((JPanel) cmp).getComponents()) {
					if (c == component) {
						break search;
					}
				}
				i++;
			}
		}
		rightPanel.remove(i);
	}

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);

		int y = 0;
		g.setColor(Color.GRAY);
		g.drawLine(0, y, getWidth(), y);
		y++;

		g.setColor(Color.WHITE);
		g.drawLine(0, y, getWidth(), y);
		// y++;
		//
		// g.setColor(new Color(218, 215, 201));
		// g.drawLine(0, y, getWidth(), y);
		// y++;
		//
		// g.setColor(new Color(233, 231, 217));
		// g.drawLine(0, y, getWidth(), y);
		//
		// y = getHeight() - 3;
		//
		// g.setColor(new Color(233, 232, 218));
		// g.drawLine(0, y, getWidth(), y);
		// y++;
		//
		// g.setColor(new Color(233, 231, 216));
		// g.drawLine(0, y, getWidth(), y);
		// y++;
		//
		// g.setColor(new Color(221, 221, 220));
		// g.drawLine(0, y, getWidth(), y);
	}

}
